﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using PrinterMasterClient;
namespace PrinteMaster
{
    public partial class 打印机状态 : Form
    {
        public static 打印机状态 m_this;
        public static 打印机状态 getInstance()
        {
            if (m_this == null)
                打印机状态.create();
            return m_this;
        }

        public static 打印机状态 create()
        {
            打印机状态 d = new 打印机状态();
            m_this = d;
            d.Show();
            return d;
        }

        public 打印机状态()
        {
            InitializeComponent();
            uint lastError;
            PrinterAPI.getInstance().enumPrinter(out lastError);
        }

        private void listBox1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        private void timer3sec_Tick(object sender, EventArgs e)
        {
            uint lastError;
            List<string> text;
            int state;
            for (int i = 0; i < PrinterAPI.getPrinterQueues().Count; i++)
            {
                PrinterAPI.getInstance().getPrinterState(PrinterAPI.m_PrinterQueues[i].name, out lastError, out text, out state);
                for (int j = 0; j < text.Count; j++)
                {
                    listBox1.Items.Add("["+PrinterAPI.m_PrinterQueues[i].name+"]"+text[j]);
                }
            }
            if (listBox1.Items.Count > 0)
            {
                button1.Enabled = true;
                this.TopMost = true;
            }
        }

        private void 打印机状态_Load(object sender, EventArgs e)
        {
            button1.Enabled = false;
            this.TopMost = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            button1.Enabled = false;
            this.TopMost = false;
            listBox1.Items.Clear();
        }

        private void listBox1_DrawItem(object sender, DrawItemEventArgs e)
        {
            //base;
            /*
            listBox1.DrawMode = DrawMode.OwnerDrawFixed;
            // Draw the background of the ListBox control for each item.
            e.DrawBackground();
            // Draw the current item text based on the current Font and the custom brush settings.
            e.Graphics.DrawString(listBox1.Items[e.Index].ToString(), e.Font, Brushes.Red, e.Bounds, StringFormat.GenericDefault);
            // If the ListBox has focus, draw a focus rectangle around the selected item.
            e.DrawFocusRectangle();
             * */
        }


    }
}
